package com.houger.ddd.seckill.template.service;

import com.houger.ddd.seckill.infra.entity.ActivityInstance;
import com.houger.ddd.seckill.repository.*;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Objects;


/**
 * @author Houger.
 * @date 2024年05月16日 18:08.
 */
@Service
public class ActivityInstanceService {
    @Resource
    private ActivityInstanceRepository activityInstanceRepository;


    public ActivityInstance save(final ActivityInstance instance) {
        return activityInstanceRepository.save(instance);
    }

    public int updateStatus(final Long instanceId, final int fromStatus, final int toStatus, final Long version) {
        if (Objects.isNull(version)){
            return activityInstanceRepository.updateStatus(instanceId,fromStatus,toStatus);
        }
        return activityInstanceRepository.updateStatus(instanceId,fromStatus,toStatus,version);
    }
}
